package org.shangrila.bme.mb;

/**
 * bme实体公共下拉数据服务：BmeCustomer/BmeMaterial
 */
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.shangrila.bme.eo.BmeContProd;
import org.shangrila.bme.eo.BmeContract;
import org.shangrila.bme.eo.BmeCustomer;
import org.shangrila.bme.eo.BmeMaterial;
import org.shangrila.bme.eo.BmePurchOrder;
import org.shangrila.bme.eo.BmeSupplier;
import org.shangrila.comm.dao.DbAccess;
 
@Named(value="bmeCommEntityService")
@ApplicationScoped
public class BmeCommEntityService {
	
	@Inject
	private DbAccess db;
	
	private List<BmeContProd> bmeContProds;
	
    @PostConstruct
    public void init() {

    }
         
    public List<BmeCustomer> getBmeCustomers() {
        return db.findAll(BmeCustomer.class);
    }
    public List<BmeMaterial> getBmeMaterials() {
        return db.findAll(BmeMaterial.class);
    }

	public List<BmeSupplier> getBmeSuppliers() {
		return db.findAll(BmeSupplier.class);
	}

	public List<BmeContract> getBmeContracts() {
		return db.findAll(BmeContract.class);
	}
	
	public List<BmePurchOrder> getBmePurchOrderBySupplierId(String supplierId) {
		String sql = "SELECT m FROM BmePurchOrder m WHERE m.bmeSupplier.id=?1";	
		return db.findBySql(sql,new Object[]{supplierId});
	}
	
	public List<BmeContract> getBmeContractsBySupplierId(String supplierId) {
		String sql = "SELECT m FROM BmeContract m WHERE m.supplierId=?1";	
		return db.findBySql(sql,new Object[]{supplierId});
	}

	public List<BmeContProd> getBmeContProds() {
		return bmeContProds;
	}

	public void setBmeContProd(List<BmeContProd> bmeContProds) {
		this.bmeContProds = bmeContProds;
	}
}